<!DOCTYPE html>
<html>
<!-- Created by GNU Texinfo 7.1.1, https://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- Copyright © 1988-2023 Free Software Foundation, Inc.

Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Funding Free Software", the Front-Cover
Texts being (a) (see below), and with the Back-Cover Texts being (b)
(see below).  A copy of the license is included in the section entitled
"GNU Free Documentation License".

(a) The FSF's Front-Cover Text is:

A GNU Manual

(b) The FSF's Back-Cover Text is:

You have freedom to copy and modify this GNU Manual, like GNU
     software.  Copies published by the Free Software Foundation raise
     funds for GNU development. -->
<title>Back End (GNU Compiler Collection (GCC) Internals)</title>

<meta name="description" content="Back End (GNU Compiler Collection (GCC) Internals)">
<meta name="keywords" content="Back End (GNU Compiler Collection (GCC) Internals)">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta name="viewport" content="width=device-width,initial-scale=1">

<link href="index.html" rel="start" title="Top">
<link href="Option-Index.html" rel="index" title="Option Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="gcc-Directory.html" rel="up" title="gcc Directory">
<link href="Front-End.html" rel="prev" title="Front End">
<style type="text/css">
<!--
a.copiable-link {visibility: hidden; text-decoration: none; line-height: 0em}
div.example {margin-left: 3.2em}
span:hover a.copiable-link {visibility: visible}
ul.mark-bullet {list-style-type: disc}
-->
</style>


</head>

<body lang="en">
<div class="subsection-level-extent" id="Back-End">
<div class="nav-panel">
<p>
Previous: <a href="Front-End.html" accesskey="p" rel="prev">Anatomy of a Language Front End</a>, Up: <a href="gcc-Directory.html" accesskey="u" rel="up">The <samp class="file">gcc</samp> Subdirectory</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<h4 class="subsection" id="Anatomy-of-a-Target-Back-End"><span>6.3.9 Anatomy of a Target Back End<a class="copiable-link" href="#Anatomy-of-a-Target-Back-End"> &para;</a></span></h4>

<p>A back end for a target architecture in GCC has the following parts:
</p>
<ul class="itemize mark-bullet">
<li>A directory <samp class="file"><var class="var">machine</var></samp> under <samp class="file">gcc/config</samp>, containing a
machine description <samp class="file"><var class="var">machine</var>.md</samp> file (see <a class="pxref" href="Machine-Desc.html">Machine Descriptions</a>), header files <samp class="file"><var class="var">machine</var>.h</samp> and
<samp class="file"><var class="var">machine</var>-protos.h</samp> and a source file <samp class="file"><var class="var">machine</var>.c</samp>
(see <a class="pxref" href="Target-Macros.html">Target Description Macros and Functions</a>),
possibly a target Makefile fragment <samp class="file">t-<var class="var">machine</var></samp>
(see <a class="pxref" href="Target-Fragment.html">The Target Makefile Fragment</a>), and maybe
some other files.  The names of these files may be changed from the
defaults given by explicit specifications in <samp class="file">config.gcc</samp>.
</li><li>If necessary, a file <samp class="file"><var class="var">machine</var>-modes.def</samp> in the
<samp class="file"><var class="var">machine</var></samp> directory, containing additional machine modes to
represent condition codes.  See <a class="xref" href="Condition-Code.html">Condition Code Status</a>, for further details.
</li><li>An optional <samp class="file"><var class="var">machine</var>.opt</samp> file in the <samp class="file"><var class="var">machine</var></samp>
directory, containing a list of target-specific options.  You can also
add other option files using the <code class="code">extra_options</code> variable in
<samp class="file">config.gcc</samp>.  See <a class="xref" href="Options.html">Option specification files</a>.
</li><li>Entries in <samp class="file">config.gcc</samp> (see <a class="pxref" href="System-Config.html">The
<samp class="file">config.gcc</samp> File</a>) for the systems with this target
architecture.
</li><li>Documentation in <samp class="file">gcc/doc/invoke.texi</samp> for any command-line
options supported by this target (see <a class="pxref" href="Run_002dtime-Target.html">Run-time
Target Specification</a>).  This means both entries in the summary table
of options and details of the individual options.
</li><li>Documentation in <samp class="file">gcc/doc/extend.texi</samp> for any target-specific
attributes supported (see <a class="pxref" href="Target-Attributes.html">Defining
target-specific uses of <code class="code">__attribute__</code></a>), including where the
same attribute is already supported on some targets, which are
enumerated in the manual.
</li><li>Documentation in <samp class="file">gcc/doc/extend.texi</samp> for any target-specific
pragmas supported.
</li><li>Documentation in <samp class="file">gcc/doc/extend.texi</samp> of any target-specific
built-in functions supported.
</li><li>Documentation in <samp class="file">gcc/doc/extend.texi</samp> of any target-specific
format checking styles supported.
</li><li>Documentation in <samp class="file">gcc/doc/md.texi</samp> of any target-specific
constraint letters (see <a class="pxref" href="Machine-Constraints.html">Constraints for
Particular Machines</a>).
</li><li>A note in <samp class="file">gcc/doc/contrib.texi</samp> under the person or people who
contributed the target support.
</li><li>Entries in <samp class="file">gcc/doc/install.texi</samp> for all target triplets
supported with this target architecture, giving details of any special
notes about installation for this target, or saying that there are no
special notes if there are none.
</li><li>Possibly other support outside the <samp class="file">gcc</samp> directory for runtime
libraries.  FIXME: reference docs for this.  The <code class="code">libstdc++</code> porting
manual needs to be installed as info for this to work, or to be a
chapter of this manual.
</li></ul>

<p>The <samp class="file"><var class="var">machine</var>.h</samp> header is included very early in GCC&rsquo;s
standard sequence of header files, while <samp class="file"><var class="var">machine</var>-protos.h</samp>
is included late in the sequence.  Thus <samp class="file"><var class="var">machine</var>-protos.h</samp>
can include declarations referencing types that are not defined when
<samp class="file"><var class="var">machine</var>.h</samp> is included, specifically including those from
<samp class="file">rtl.h</samp> and <samp class="file">tree.h</samp>.  Since both RTL and tree types may not
be available in every context where <samp class="file"><var class="var">machine</var>-protos.h</samp> is
included, in this file you should guard declarations using these types
inside appropriate <code class="code">#ifdef RTX_CODE</code> or <code class="code">#ifdef TREE_CODE</code>
conditional code segments.
</p>
<p>If the backend uses shared data structures that require <code class="code">GTY</code> markers 
for garbage collection (see <a class="pxref" href="Type-Information.html">Memory Management and Type Information</a>), you must declare those
in <samp class="file"><var class="var">machine</var>.h</samp> rather than <samp class="file"><var class="var">machine</var>-protos.h</samp>.  
Any definitions required for building libgcc must also go in
<samp class="file"><var class="var">machine</var>.h</samp>.
</p>
<p>GCC uses the macro <code class="code">IN_TARGET_CODE</code> to distinguish between
machine-specific <samp class="file">.c</samp> and <samp class="file">.cc</samp> files and
machine-independent <samp class="file">.c</samp> and <samp class="file">.cc</samp> files.  Machine-specific
files should use the directive:
</p>
<div class="example">
<pre class="example-preformatted">#define IN_TARGET_CODE 1
</pre></div>

<p>before including <code class="code">config.h</code>.
</p>
<p>If the back end is added to the official GCC source repository, the
following are also necessary:
</p>
<ul class="itemize mark-bullet">
<li>An entry for the target architecture in <samp class="file">readings.html</samp> on the
GCC web site, with any relevant links.
</li><li>Details of the properties of the back end and target architecture in
<samp class="file">backends.html</samp> on the GCC web site.
</li><li>A news item about the contribution of support for that target
architecture, in <samp class="file">index.html</samp> on the GCC web site.
</li><li>Normally, one or more maintainers of that target listed in
<samp class="file">MAINTAINERS</samp>.  Some existing architectures may be unmaintained,
but it would be unusual to add support for a target that does not have
a maintainer when support is added.
</li><li>Target triplets covering all <samp class="file">config.gcc</samp> stanzas for the target,
in the list in <samp class="file">contrib/config-list.mk</samp>.
</li></ul>

</div>
<hr>
<div class="nav-panel">
<p>
Previous: <a href="Front-End.html">Anatomy of a Language Front End</a>, Up: <a href="gcc-Directory.html">The <samp class="file">gcc</samp> Subdirectory</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Option-Index.html" title="Index" rel="index">Index</a>]</p>
</div>



</body>
</html>
